package com.zhouu.example.core.message;

import com.zhouu.example.core.util.SpringBeanUtil;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

import java.io.Serializable;

/**
 * 接口返回结果
 *
 * @author zhouu
 * @date 2021-02-23 22:28
 */
public class Result<T> implements Serializable {

    /** 错误码 */
    private String code;

    /** 错误信息 */
    private String message;

    /** 返回数据 */
    private T data;

    private static final long serialVersionUID = 1L;

    public Result() {

    }

    public Result(String code, T data) {
        this.code = code;
        this.message = SpringBeanUtil.getBean(MessageSource.class).getMessage(code, null, LocaleContextHolder.getLocale());
        this.data = data;
    }

    public Result(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
